package com.wangdong.wddemo;



import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v7.app.AppCompatActivity;
import android.widget.TextView;

import java.lang.ref.WeakReference;
import java.util.HashMap;
import java.util.Map;

public class MainActivity extends AppCompatActivity {
    private TextView tv;
    Map map = new HashMap();
    private MHandler handler = new MHandler(this);

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    private class MHandler extends Handler{

        WeakReference<MainActivity> activity ;

        /**
         * Default constructor associates this handler with the {@link Looper} for the
         * current thread.
         * <p>
         * If this thread does not have a looper, this handler won't be able to receive messages
         * so an exception is thrown.
         */
        public MHandler(MainActivity aty) {
            activity = new WeakReference<MainActivity>(aty);
        }

        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
        }
    }

    private void sendMMessage(){
        Message message = handler.obtainMessage();
        message.what = 0;
        message.obj = "wangdong";
        message.arg1=9;
        handler.sendMessage(message);
    }
}

